/* eslint-disable */
const { list } = require('./src/mock')
const bodyParser = require('body-parser')
module.exports = {
	devServer: {
		before(app) {
			app.use(bodyParser.json())

			app.get('/api/list', (req, res) => {
				const {
					pageCode = 1,
					pageSize = 10,
					type = '全部',
					searchValue = ''
				} = req.query

				const newList = list.filter(v => {
					// 精确查找
					if (type === '全部') return true
					return v.type === type
				}).filter(v => {
					// 模糊搜索
					return v.key.includes(searchValue) || v.title.includes(searchValue) || v.id.toString().includes(searchValue)
				})


				const data = newList.slice((pageCode - 1) * pageSize, pageCode * pageSize);

				if ((pageCode - 1) * pageSize < newList.length && pageCode >= 1) {
					res.send({
						code: 0,
						data: data,
						total: newList.length
					})
				} else {
					res.send({
						code: 1,
						data: null,
						mess: '非法页码或者超过最大数据请求'
					})
				}

			})
		}
	}
}